/***************************************************************************
 *  Copyright (c) 2005 Chih-Chung Chang                                    *
 *  Parts copyright (c) 2006 Michael Olson                                 *
 *  Copyright (C) 2007-2008 by Fehmi "Canavar" SAGLAM                      *
 *  canavar@fehmicans.net                                                  *
 *                                                                         *
 *  This file is part of sTerm.                                            *
 *                                                                         *
 *  sTerm is free software; you can redistribute it and/or modify          *
 *  it under the terms of the GNU General Public License as published by   *
 *  the Free Software Foundation; either version 3 of the License, or      *
 *  (at your option) any later version.                                    *
 *                                                                         *
 *  sTerm is distributed in the hope that it will be useful,               *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *  GNU General Public License for more details.                           *
 *                                                                         *
 *  You should have received a copy of the GNU General Public License      *
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>   *
 ***************************************************************************/

#ifndef _stermvalueparser_h__
#define _stermvalueparser_h__

class StermValueParser
{
    public:
        static char *Parse(char *value)
        {
            bool flag = false;
            int ret_counter = 0, ascii_counter = 0/*max value is 3*/;
            char ascii_value[4];
            char *ret_value = value;

            while(*value)
            {
                if(*value == '#')
                {
                    if(flag)
                    {
                        flag = false;
                        if(!ascii_counter)
                            ret_value[ret_counter++] = '#';
                        else
                        {
                            ascii_value[ascii_counter] = 0;
#ifdef __debug__
                            printf("value: %s\n", ascii_value);
#endif
                            ret_value[ret_counter++] = atoi(ascii_value);
                        }
                    }
                    else
                    {
                        flag = true;
                        ascii_counter = 0;
                    } 
                }
                else
                {
                    if(flag)
                    {
                        if(ascii_counter == 3)
                            return " ";
                        ascii_value[ascii_counter++] = *value;
                    }
                    else
                    {
                        ret_value[ret_counter++] = *value;
                    }
                }
                value++;
            }		 

            ret_value[ret_counter] = 0;
            return ret_value;
        }
};

#endif
